#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys
import os
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

from app.core.database import engine, Base, SessionLocal
from app.models.base_model import User, Role, Department, Employee
from sqlalchemy import inspect

def check_database():
    """检查数据库状态"""
    print("\n=== 检查数据库表 ===")
    inspector = inspect(engine)
    tables = inspector.get_table_names()
    print("已存在的表:", tables)

    db = SessionLocal()
    try:
        print("\n=== 检查用户数据 ===")
        users = db.query(User).all()
        for user in users:
            print(f"用户ID: {user.id}, 用户名: {user.username}, 角色ID: {user.role_id}")

        print("\n=== 检查角色数据 ===")
        roles = db.query(Role).all()
        for role in roles:
            print(f"角色ID: {role.id}, 名称: {role.name}")

    except Exception as e:
        print(f"检查数据时出错: {e}")
    finally:
        db.close()

if __name__ == "__main__":
    check_database() 